home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / server.arc / CLIENT.C next >
Text File  |  1989-12-06  |  7KB  |  183 lines

  1. client.c   
  2.    
  3. /*------------------------------------------------*    
  4.  *     TLA Client                                 *    
  5.  *                                                *    
  6.  *     Written by: Stephen T. Bunch               *    
  7.  *                 API Development                *    
  8.  *                                                *    
  9.  *     Date:       July 11, 1989                  *    
  10.  *                                                *    
  11.  *------------------------------------------------*/    
  12. #include       <stdio.h>    
  13. #define        INCL_BASE    
  14. #include       <os2.h>    
  15. #include       <nwcalls.h>    
  16. #include       <malloc.h>    
  17. #include       "server.h"    
  18.     
  19. #define    STACK_SIZE    2000    
  20. #define    PIPENAME      "\\PIPE\\TLAPIPE"    
  21. char pipeName[80];    
  22.     
  23. /*--------------------------------------------------------------*/    
  24. main(int argc,char *argv[])    
  25. {    
  26.     char fileName[20];    
  27.     struct COMMBUFFER outBuffer;    
  28.     char ch;    
  29.     
  30.     GetServerName();    
  31.     do {    
  32.         PrintMenu();    
  33.         memset(&outBuffer, 0, sizeof(struct COMMBUFFER));    
  34.         switch (ch = getche()) {    
  35.             case '3':        /* enter new information from a file */    
  36.                 printf("\n\nEnter filename: ");    
  37.                 gets(fileName);    
  38.                 NewInput(fileName);    
  39.                 break;    
  40.             case '1':        /* search for a single tla */    
  41.                 QueryData(FALSE, &outBuffer);    
  42.                 PrintCommBuffer(&outBuffer);    
  43.                 break;    
  44.             case '2':        /* search for multiple tlas */     
  45.                 QueryData(TRUE, &outBuffer);    
  46.                 break;    
  47.             }    
  48.     } while (ch != '4');    
  49. }    
  50.     
  51. /*--------------------------------------------------------------*/    
  52. PrintMenu()    
  53. {    
  54.     system("cls");    
  55.     printf("\n\tWelcome to the TLA server");    
  56.     printf("\n\nSelections are:");    
  57.     printf("\n\t1) Search for single TLA");    
  58.     printf("\n\t2) Search for multiple TLAs");    
  59.     printf("\n\t3) Add new TLAs from a file");    
  60.     printf("\n\t4) Quit");    
  61.     printf("\n\n\tEnter selection: ");    
  62. }    
  63.     
  64. /*--------------------------------------------------------------*    
  65.  * GetServerName gets the server name if we are a remote client *    
  66.  *--------------------------------------------------------------*/    
  67. GetServerName()    
  68. {    
  69.     char serverName[20], ch;    
  70.     
  71.     printf("Are you a Remote Client (not on same wrkstn as server) ?(Y/N) :");    
  72.     ch = getche();    
  73.     if (ch == 'y' || ch == 'Y') {    
  74.         strcpy(pipeName,"\\\\");    
  75.         printf("\n\nEnter Server Name :");    
  76.         gets(serverName);    
  77.         strcat(pipeName, serverName);    
  78.     }    
  79.     strcat(pipeName, PIPENAME);    
  80. }    
  81.     
  82. /*-------------------------------------------------------*    
  83.  * NewInput reads in the new TLAs to add to out database *    
  84.  *-------------------------------------------------------*/    
  85. NewInput(fileName)    
  86. char *fileName;    
  87. {    
  88.     struct COMMBUFFER commBuffer, outBuffer;    
  89.     FILE *finput;    
  90.     
  91.     if ((finput = fopen(fileName, "r")) == NULL) {    
  92.         printf("\nError opening input file.");    
  93.         exit(0);    
  94.     }    
  95.     
  96.     while (TRUE){    
  97.         memset(&commBuffer, 0, sizeof(struct COMMBUFFER));    
  98.         ReadSring(commBuffer.record.tla, TLA_SIZE, finput);    
  99.         if (strcmp(commBuffer.record.tla, "quit") == 0)    
  100.             break;    
  101.         ReadSring(commBuffer.record.expanded, 80, finput);    
  102.         ReadSring(commBuffer.record.explain, 80, finput);    
  103.         ReadSring(&commBuffer.record.explain[80], 80, finput);    
  104.         commBuffer.type |= ADD_TO_LIST;    
  105.         SendMessage(&commBuffer, &outBuffer);    
  106.     }    
  107. }    
  108.     
  109. /*----------------------------------------------------------*    
  110.  * ReadString reads an input string from the open file sent *    
  111.  *----------------------------------------------------------*/    
  112. ReadSring(buffer, size, file)    
  113. char buffer[];    
  114. int size;    
  115. FILE *file;    
  116. {    
  117.     int i;    
  118.     char ch;    
  119.     
  120.     for (i=0; i<size-1; i++) {    
  121.         if ((ch = fgetc(file)) == '\n')    
  122.             break;    
  123.         else    
  124.             buffer[i] = ch;    
  125.     }    
  126.     buffer[i] = '\0';    
  127. }    
  128.     
  129. /*--------------------------------------------------------------*    
  130.  * QueryData gets the tla from the user and send in the request *    
  131.  *--------------------------------------------------------------*/    
  132. QueryData(queryMany, outBuffer)    
  133. WORD queryMany;    
  134. struct COMMBUFFER *outBuffer;    
  135. {    
  136.     struct COMMBUFFER commBuffer;    
  137.     
  138.     system("cls");    
  139.     do {    
  140.         memset(&commBuffer, 0, sizeof(struct COMMBUFFER));    
  141.         do    {    
  142.             printf("\nEnter TLA to find (q to quit): ");    
  143.             gets(commBuffer.record.tla);    
  144.         } while (strlen(commBuffer.record.tla) < 1);    
  145.         if (strcmp(commBuffer.record.tla, "q") == 0)    
  146.             break;    
  147.         commBuffer.type |= QUERY;    
  148.         SendMessage(&commBuffer, outBuffer);    
  149.         if (queryMany)    
  150.             PrintCommBuffer(outBuffer);    
  151.     }    while (queryMany);    
  152. }    
  153.     
  154. /*--------------------------------------------------------------------*    
  155.  * SendMessage sends the communication buffer over the pipe and reads *    
  156.  * the response                                                       *    
  157.  *--------------------------------------------------------------------*/    
  158. SendMessage(commBuffer, outBuffer)    
  159. struct COMMBUFFER *commBuffer, *outBuffer;    
  160. {    
  161.     ULONG timeOut;    
  162.     USHORT bytesRead, err;    
  163.     
  164.     timeOut = 10000L;                 /* time out after 10 seconds   */    
  165.     do {                              /* send messages down the pipe */    
  166.         err = DosCallNmPipe(pipeName,    (char *)commBuffer,    
  167.                (USHORT)sizeof(struct COMMBUFFER), (char *)outBuffer,    
  168.                 (USHORT)sizeof(struct COMMBUFFER), &bytesRead, timeOut);    
  169.     } while (err == ERROR_PIPE_BUSY);    
  170.     if (err)    
  171.         printf("DosCallNmPipe Error : %d", err);    
  172. }    
  173.     
  174.     
  175. /*--------------------------------------------------------------*/    
  176. PrintCommBuffer(commBuffer)    
  177. struct COMMBUFFER *commBuffer;    
  178. {    
  179.     printf("\n%s : %-60s", commBuffer->record.tla, commBuffer->record.expanded);    
  180.     printf("\n%-80s ", commBuffer->record.explain);    
  181.     printf("%-79s ", &(commBuffer->record.explain[80]));    
  182. }    
  183.